<?php

declare (strict_types=1);

namespace App\Model;

use Qbhy\HyperfAuth\Authenticatable;
use Qbhy\HyperfAuth\UserProvider;

/**
 * @property int $id 主健
 * @property string $username 用户名
 * @property string $salt
 * @property string $password 用户密码
 * @property string $mark 用户备注
 * @property int $group_id 分组ID
 * @property string $nickname 用户昵称
 * @property string $avatar 用户头像
 * @property string $phone 手机号码
 * @property string $create_time 添加时间
 * @property string $update_time 最后一次登录时间
 * @property string $last_ip 最后一次登录ip
 * @property string $last_login_time
 * @property int $status 1为正常，0为禁止
 * @property int $spread_uid 推广元id
 * @property string $spread_time 推广员关联时间
 * @property int $spread_count 下级人数
 * @property string $pay_password 支付密码
 * @property string $compellation 姓名
 * @property string $email 邮箱
 * @property int $gender 1男2女3为未知
 * @property int $dict_customer_type_id 客户类型（字典的id）
 * @property int $customer_source 1官网2抖音3快手4拼多多5等等
 * @property string $mini_openid
 */
class AppUser extends Model implements Authenticatable
{
    public $timestamps=false;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'app_user';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['id', 'username', 'salt', 'password', 'mark', 'group_id', 'nickname', 'avatar', 'phone', 'create_time', 'update_time', 'last_ip', 'last_login_time', 'status', 'spread_uid', 'spread_time', 'spread_count', 'pay_password', 'compellation', 'email', 'gender', 'dict_customer_type_id', 'customer_source', 'mini_openid'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'string', 'group_id' => 'integer', 'status' => 'integer', 'spread_uid' => 'integer', 'spread_count' => 'integer', 'gender' => 'integer', 'dict_customer_type_id' => 'integer', 'customer_source' => 'integer'];


    /**
     * @return \Hyperf\Database\Model\Relations\HasOne
     */
    public function shop()
    {
        return $this->hasOne(FlyShop::class, 'user_id', 'id');
    }

    public function getId()
    {
        // 返回用户id
        return $this->id;
    }

    public static function retrieveById($key): ?Authenticatable
    {
        // 通过id查找用户
        return self::query()->find($key);
    }
}